home *** CD-ROM | disk | FTP | other *** search
/ Amiga Game-Power / Amiga Game-Power.iso / anwendungen / gw print / structurebrowser_v1.3 / sources / sb.c < prev    next >
C/C++ Source or Header  |  1994-05-20  |  4KB  |  163 lines

  1. /* sb.c
  2.  
  3.    Structure Browser 1.2
  4.  
  5.    (c) 1987 Transactor Magazine
  6.  
  7.    Source and program free to distribute, not to sell.
  8.  
  9.    Structure Browser is designed to grow, to cover more system structures.
  10.    Please feel free to lend a hand, but we ask that you help us keep its
  11.    growth under control by submitting proposed changes to us either via
  12.    mail at the Transactor (address below) or on Compuserve's AmigaForum,
  13.    Commodore programming forum (CBMPRG), or Commodore communications forum
  14.    (CBMCOM). For details on how to implement new structures, see the magazine
  15.    article in The Transactor, Volume 7, Issue 6.
  16.  
  17.    The Transactor
  18.    501 Alden Road
  19.    P.O. Box 3250
  20.    Markham Industrial Park
  21.    Markham, Ontario
  22.    Canada L3R 9Z9
  23.  
  24.    on Compuserve:
  25.    Chris Zamara      76703,4245
  26.    Nick Sullivan     76703,4353
  27.  
  28.    March 26, 1987
  29. */
  30.  
  31. #include "header/sb.h"
  32. #include "header/trap.h"
  33.  
  34. extern struct IntuitionBase *IntuitionBase;
  35. extern struct IntuiText ChoiceText[], BackIText;
  36.  
  37. APTR OpenLibrary();
  38.  
  39. extern int MyHandler();
  40.  
  41. int level = 0;
  42. BOOL StartedFromCLI;
  43.  
  44. /* main
  45.  
  46.    SB starts out at the Library level. So far, only Intuition is covered, so
  47.    there is only one menu option at this level - IntuitionBase.
  48. */
  49.  
  50. main (argc, argv)
  51. int argc;
  52. char **argv;
  53. {
  54. int choice = -1;
  55.  
  56.    StartedFromCLI = argc > 0;
  57.    SetupGadg();
  58.    SetTrap();
  59.    OpenStuff(); /* open intuition library & window */
  60.  
  61.    while (choice)
  62.    {
  63.       putHeader("Choose a Library structure", NULL);
  64.       ChoiceText[0].IText = (UBYTE *)" Intuition      struct Library";
  65.       BackIText.IText = (UBYTE *)"  Quit  Program ";
  66.       switch (choice = GetChoice(1))
  67.       {
  68.          case 1:
  69.             PrIntuiBase ("The IntuitionBase structure", IntuitionBase);
  70.             break;
  71.       }
  72.    }
  73.    CloseOut();
  74. }
  75.  
  76.  
  77. /* PrIntuiBase
  78.  
  79.    All 5 members of the IntuitionBase structure are covered. The handlers
  80.    for these are in other modules.
  81. */
  82.  
  83. PrIntuiBase (string, IBase)
  84. char *string;
  85. struct IntuitionBase *IBase;
  86. {
  87. static struct StructData structdata[] = {
  88.    { " LibNode",           "struct Library",  PRNULL, SZ(Library) },
  89.    { " ViewLord",          "struct View",     PRNULL, SZ(View)    },
  90.    { " ActiveWindow",      "struct Window *", PRPTR,  PTRSIZE     },
  91.    { " ActiveScreen",      "struct Screen *", PRPTR,  PTRSIZE     },
  92.    { " FirstScreen",       "struct Screen *", PRPTR,  PTRSIZE     }
  93. };
  94.  
  95. int i, sum;
  96. int choice = -1;
  97.  
  98.    level++;
  99.  
  100.    while (choice)
  101.    {
  102.       sum = SetOptionText(string, structdata, (APTR)IBase, DATASIZE, 0);
  103.  
  104.       switch (choice = GetChoice(DATASIZE))
  105.       {
  106.          case 1:
  107.             PrLibrary("The Library structure in IntuitionBase",
  108.                &IBase->LibNode);
  109.             break;
  110.          case 2:
  111.             PrView("Intuition's View of the world", &IBase->ViewLord);
  112.             break;
  113.          case 3:
  114.             if (IBase->ActiveWindow)
  115.                PrWindow("The currently active window", IBase->ActiveWindow);
  116.             break;
  117.          case 4:
  118.             PrScreen("The currently active screen", IBase->ActiveScreen);
  119.             break;
  120.          case 5:
  121.             PrScreen("The first screen on Intuition's list",
  122.                IBase->FirstScreen);
  123.             break;
  124.       }
  125.    }
  126.    level--;
  127. }
  128.  
  129.  
  130. /* SetTrap
  131.  
  132.    Point the Software Error vector at our own handler (MyHandler(), below)
  133. */
  134.  
  135. SetTrap ()
  136. {
  137.    MyTask = FindTask(0L);
  138.    MyTask->tc_TrapCode = (APTR)MyTrap.MLcode;
  139.    MyTrap.Code = MyHandler;
  140. }
  141.  
  142.  
  143. /* MyHandler
  144.  
  145.    What to do in case of a Software Error - for example, if we tried to
  146.    indirect through a pointer in a structure that has been deallocated since
  147.    the user started to examine it.
  148. */
  149.  
  150. MyHandler ()
  151. {
  152.    CloseOut();
  153.  
  154.    /* print message, or if started from Wbench, just DisplayBeep and exit */
  155.    if (StartedFromCLI)
  156.       printf("Sorry - got a Software Error condition - trap #%ld\n",
  157.               MyTrap.TrapNum);
  158.    else
  159.       DisplayBeep(IntuitionBase->ActiveScreen);
  160.  
  161.    exit(1000 + MyTrap.TrapNum);
  162. }
  163.